package com.cc.mapper;

import com.cc.config.SpringConfig;
import com.cc.entity.Attendance;
import com.cc.entity.EmployeeAttendance;
import com.cc.entity.Employees;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.InputStream;
import java.util.Date;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class EmploysseMapper {
    @Autowired
    private EmployeesMapper employeesMapper;
    @Autowired
    private EmployeeInsuranceMapper insuranceMapper;
    @Autowired
    private EmployeeAttendanceMapper attendanceMapper;


    @Test
    public void findAll(){
       int count=employeesMapper.findAll();
        System.out.println(count);
    }
    @Test
    public void selectEmployeeByEmployeeNo() {
        Employees employee = employeesMapper.selectEmployeeByEmployeeNo("EMP2023001");
        System.out.println("员工信息: " + employee);
    }
    @Test
    public void selectByName(){
        List<Employees> list=employeesMapper.selectByName("张",101);
        System.out.println(list);
    }
    @Test
    public void getEmployeeAttendanceCount(){
        List<Attendance> list=attendanceMapper.selectAttendanceCount();
        System.out.println(list);
    }
    @Test
    public void deleteByInactiveEmployees(){
        attendanceMapper.deleteByInactiveEmployees();
    }
    @Test
    public void selectByemployeeno(){
       Employees employees = employeesMapper.selectByemployeeno("EMP2023001");
        System.out.println(employees);
    }
    @Test
    public void insert(){
        Employees employee=new Employees();
        employee.setEmployeeNo("EMP2023003");
        employee.setName("王五");
        employee.setGender("M");
        employee.setDepartmentId(101);
        employee.setPosition("香蕉");
        employee.setHireDate(new Date());
        employee.setStatus(1);
        employee.setCreatedAt(new Date());
        employee.setUpdatedAt(new Date());
        int count=employeesMapper.insert(employee);
        if (count > 0) {
            System.out.println("成功");
        } else {
            System.out.println("失败");
        }
    }
}
